<?php
if(@$_POST['btnnhatky']){
	$tc->add_nhatky();
	header('location:http://'.$domain.'/index.html?user='.$idUser.'&type=photos');
}
$view_photos = '<div id="all_view"><div id="title" style="background:#f6f7f8 url(images/photos_album.jpg) no-repeat left"><h2>Album ảnh</h2>'.$create_photo.'<div style="clear:both; height:1px"></div></div>
'.$create_frm_album.'<div style="width:100%; height:15px; background:url(images/arrow.jpg) no-repeat center bottom"></div><div id="photos">';
$i = 0;
$photos = $tc->view_photo_album($user);
while($row_photos = mysql_fetch_array($photos)){
	if($row_photos['info']==''){/*album anh*/
		if($row_photos['share_id']!=3){
			$i++;
			if($row_photos['anhdaidien'] != '') $view='<a href="index.html?user='.$user.'&type=all-pic&album='.$row_photos['id'].'"><img src="'.url_hinh_photo_300x200.$row_photos['anhdaidien'].'.jpg" alt="photos album" /><div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="title">'.$row_photos['name'].'</div></a>';
			else $view='<a href="index.html?user='.$user.'&type=all-pic&album='.$row_photos['id'].'"><img src="'.url_hinh_photo_300x200.$tc->album_rand_anhdd($row_photos['id']).'.jpg" alt="photos album" /><div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="title">'.$row_photos['name'].'</div></a>';
			if($i%2 == 1) $view_photos .= '<div class="item"><div class="col1">'.$view.'</div>';
			else $view_photos .= '<div class="col2">'.$view.'</div></div>';
		}elseif($row_photos['user_id']==$idUser){
			$i++;
			if($row_photos['anhdaidien'] != '') $view='<a href="index.html?user='.$user.'&type=all-pic&album='.$row_photos['id'].'"><img src="'.url_hinh_photo_300x200.$row_photos['anhdaidien'].'.jpg" alt="photos album" /><div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="title">'.$row_photos['name'].'</div></a>';
			else $view='<a href="index.html?user='.$user.'&type=all-pic&album='.$row_photos['id'].'"><img src="'.url_hinh_photo_300x200.$tc->album_rand_anhdd($row_photos['id']).'.jpg" alt="photos album" /><div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="title">'.$row_photos['name'].'</div></a>';
			if($i%2 == 1) $view_photos .= '<div class="item"><div class="col1">'.$view.'</div>';
			else $view_photos .= '<div class="col2">'.$view.'</div></div>';
		}
	}else{ /*nhat ky*/
		if($row_photos['share_id']!=3){
			$i++;
			$view='<div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="info '.$row_photos['id'].'"><div class="view'.$row_photos['id'].'" style="height:154px; overflow:hidden">'.$row_photos['info'].'</div><a class="nhatky" href="javascript:;">Xem thêm</a></div><div class="title">'.$row_photos['name'].'</div>';
			if($i%2 == 1) $view_photos .= '<div class="item"><div class="col1">'.$view.'</div>';
			else $view_photos .= '<div class="col2">'.$view.'</div></div>';
		}elseif($row_photos['user_id']==$idUser){
			$i++;
			$view='<div class="date">'.$tc->wall_date($row_photos['date_create']).'</div><div class="info '.$row_photos['id'].'"><div class="view'.$row_photos['id'].'" style="height:154px; overflow:hidden">'.$row_photos['info'].'</div><a class="nhatky" href="javascript:;">Xem thêm</a></div><div class="title">'.$row_photos['name'].'</div>';
			if($i%2 == 1) $view_photos .= '<div class="item"><div class="col1">'.$view.'</div>';
			else $view_photos .= '<div class="col2">'.$view.'</div></div>';
		}
	}
}
if($i%2 != 1) echo $view_photos.'<div style="clear:both; height:80px"></div></div></div>';
else echo $view_photos.'<div style="clear:both; height:80px"></div></div></div></div>';
?>
<div id="popupContact">
    <div id="content_pic" style="width:500px; background-color:#FFF; margin:auto; padding:15px">
        <a id="popupContactClose" style="font-size:16px">[ x ] Đóng lại</a>
        <div style="padding:10px; line-height:25px; font-size:14px" id="view_nhatky"></div>
    </div>
</div>
<div id="backgroundPopup"></div>
<script type="text/javascript" src="library/jquery.form.js"></script>
<script type="text/javascript" >
$(document).ready(function(){ 
	$('#photoimg').live('change',function(){
		$("#pic_box_load").html('');
		$("#pic_box_load").html('<img src="images/loader.gif" width="150" height="19" alt="Uploading...."/>');
		$("#imageform").ajaxForm({target: '.pic_box'}).submit();
	});
	$("#frmUpload").hide();
	$("input[name=create_album]").click(function(){
		var share_id = $("select[name=share]").val();
		var name_album = $("input[name=name_album]").val();
		if(name_album!=''){
			$.post("ajax.php",{create_album:'create_album',name_album:name_album,share_id:share_id},function(){
				$("#create_id").html("<span style='color:blue'>Tạo album <b>"+name_album+"</b> thành công!</span>");
				$("input[name=create_album],input[name=name_album]").attr("disabled",true);
				$("#frmUpload").show();
			});
		}
	});
	$(".anhdaidien").live('dblclick', function(){
		var id = ($(this).attr('class')).split(" ");
		if(confirm("Bạn có muốn chọn ảnh này làm ảnh đại diện?")){
			$.post("ajax.php",{anhdaidien:'anhdaidien',id:id[1]});
		}
	});
	$('.info').click(function(){
		var id = ($(this).attr('class')).split(" ");
		var data = $('.view'+id[1]).html();
		$('#view_nhatky').html(data);
		centerPopup("fix");
		loadPopup();
		$("#popupContactClose").click(function() {
			disablePopup();
		});
		$("#backgroundPopup").click(function() {
			disablePopup();
		});
	});
}); 
</script>
<?php mysql_free_result($photos);?>